/*
 *-----------------------------------------------------------------------------
 *
 * TFinderRpcCaller.java
 *
 * This file was created from IFinderRpc.idl
 * by the Simple JavRMI backend.
 *
 * Copyright 2008-2010, Evgeny Alexeyev
 * Licensed under the EPL - v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 *
 *-----------------------------------------------------------------------------
 */

package com.googlecode.umlsynch.rpc;

import java.io.*;

import com.googlecode.umlsynch.rpc.base.TIOHandler;

import com.googlecode.umlsynch.rpc.base.IDebug;

import com.googlecode.umlsynch.rpc.base.TDebug;

import com.googlecode.umlsynch.rpc.TFileDescriptor;

import com.googlecode.umlsynch.rpc.TClassDescriptor;

import com.googlecode.umlsynch.rpc.TSearchQueryDescriptor;

import com.googlecode.umlsynch.rpc.IFinderRpc;


public class TFinderRpcCaller implements IFinderRpc
{
  TIOHandler handler;
  TDebug debug;
  
  public TFinderRpcCaller(TIOHandler hdl, IDebug dbg) {
    handler = hdl;
    debug = new TDebug(dbg);
  }
  
  public TClassDescriptor[] FindClassByName(TFileDescriptor[] searchPaths, String searchNamePattern) {
    if (!handler.connect())
      return null;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IFinderRpc"));
      handler.getObjectOutputStream().writeObject(new String("FindClassByName"));
      
      handler.getObjectOutputStream().writeObject(new String("TFileDescriptor[]"));
      handler.getObjectOutputStream().writeObject(searchPaths);
      
      handler.getObjectOutputStream().writeObject(new String("String"));
      handler.getObjectOutputStream().writeObject(new String("searchNamePattern"));
      
      TClassDescriptor[] result = null;
      data = handler.readString();
      if (data.equals("TClassDescriptor[]")) {
        result = (TClassDescriptor[]) handler.getObjectInputStream().readObject();
      } else {
        debug.Error("Recieved wrong parameter type:" + data + " expected TClassDescriptor[]");
        throw new ClassNotFoundException();
      }
      
      return result;
    }
    catch (IOException e) {
    }
    catch (ClassNotFoundException e) {
    }
    
    handler.close();
    return null;
  }; // FindClassByName
  
  public void FindValueByName(TFileDescriptor sourceFile, String namePattern) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IFinderRpc"));
      handler.getObjectOutputStream().writeObject(new String("FindValueByName"));
      
      handler.getObjectOutputStream().writeObject(new String("TFileDescriptor"));
      handler.getObjectOutputStream().writeObject(sourceFile);
      
      handler.getObjectOutputStream().writeObject(new String("String"));
      handler.getObjectOutputStream().writeObject(new String("namePattern"));
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // FindValueByName
  
  public void FindValueByType(TFileDescriptor sourceFile, String namePattern) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IFinderRpc"));
      handler.getObjectOutputStream().writeObject(new String("FindValueByType"));
      
      handler.getObjectOutputStream().writeObject(new String("TFileDescriptor"));
      handler.getObjectOutputStream().writeObject(sourceFile);
      
      handler.getObjectOutputStream().writeObject(new String("String"));
      handler.getObjectOutputStream().writeObject(new String("namePattern"));
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // FindValueByType
  
  public void SearchTextPattern(TSearchQueryDescriptor desc) {
    if (!handler.connect())
      return;
    
    String data;
    try {
    
      handler.getObjectOutputStream().writeObject(new String("IFinderRpc"));
      handler.getObjectOutputStream().writeObject(new String("SearchTextPattern"));
      
      handler.getObjectOutputStream().writeObject(new String("TSearchQueryDescriptor"));
      handler.getObjectOutputStream().writeObject(desc);
      
    }
    catch (IOException e) {
    }
    
    handler.close();
  }; // SearchTextPattern
  
}; // IFinderRpc

